package database;
import java.sql.*;

public class ColumnName{
  public static void main(String[] args) {
    System.out.println("Getting Column Names Example!");
    Connection con = null;
    String url ="jdbc:postgresql://192.168.61.205:5432/license";
    String db = "postgresql";
   // String driver = "com.mysql.jdbc.Driver";
    String user = " ";
    String pass = " ";
    try{
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection(url+db, user, pass);
      try{
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("select * from users ");
        ResultSetMetaData md = rs.getMetaData();
        int col = md.getColumnCount();
        System.out.println("Number of Column : "+ col);
        System.out.println("Columns Name: ");
        for (int i = 1; i <= col; i++){
          String col_name = md.getColumnName(i);
          System.out.println(col_name);
        }
      }
      catch (SQLException s){
        System.out.println("SQL statement is not executed!");
      }
    }
    catch (Exception e){
      e.printStackTrace();
    }
  }
}